class WebUserController < ApplicationController
  def getBaseInfoByID
    begin
      #require "json"
      webUser = WebUser.find(params[:id])
      jsonstr="{root:["+webUser.to_json()+"]}"
      render :text=>jsonstr, :layout=>false
    rescue Exception => e
      CommonHelper.infoLogger(session[:user_id],request.env["REMOTE_ADDR"],params[:controller],params[:action],e,"error")
    end
  end
  
  #乐票个人版
  def getPersonBaseInfoByID
    begin
      customer = Customer.find(session[:web_user_id])
      jsonstr="{root:["+customer.to_json()+"]}"
      render :text=>jsonstr, :layout=>false
    rescue Exception => e
      CommonHelper.infoLogger(session[:user_id],request.env["REMOTE_ADDR"],params[:controller],params[:action],e,"error")
    end
  end
  
  def setBaseInfo
    begin
      webUser = WebUser.find(session[:web_user_id])
      webUser.sex = params[:sex]
      webUser.phone = params[:phone]
      webUser.email = params[:email]
      webUser.card = params[:card]
      webUser.address = params[:address]
      webUser.company_name = params[:company_name]
      webUser.company_phone = params[:company_phone]
      webUser.company_fax = params[:company_fax]
      webUser.post_code = params[:post_code]
      webUser.save
      render :text=>nil, :layout=>false
    rescue Exception => e
      CommonHelper.infoLogger(session[:user_id],request.env["REMOTE_ADDR"],params[:controller],params[:action],e,"error")
    end
  end
  
  def setPersonBaseInfo
    begin
      customer = Customer.find(session[:web_user_id])
      customer.name = params[:name]
      customer.phone = params[:phone]
      customer.email = params[:email]
      customer.card = params[:card]
      customer.address = params[:address]
      customer.save
      render :text=>nil, :layout=>false
    rescue Exception => e
      CommonHelper.infoLogger(session[:user_id],request.env["REMOTE_ADDR"],params[:controller],params[:action],e,"error")
    end
  end
  
  def setPasswordInfo
    begin
      webUser = WebUser.find(session[:web_user_id])
      if webUser.password == params[:password]
        webUser.password = params[:new_password]
        webUser.save    
        jsonstr="{success:true}"
      else
        jsonstr="{success:false}"
      end  
      render :text=>jsonstr, :layout=>false
    rescue Exception => e
      CommonHelper.infoLogger(session[:user_id],request.env["REMOTE_ADDR"],params[:controller],params[:action],e,"error")
    end
  end
  
  #设置个人版密码
  def setPersonPasswordInfo
    begin
      customer = Customer.find(session[:web_user_id])
      if customer.password == params[:password]
        customer.password = params[:new_password]
        customer.save    
        jsonstr="{success:true}"
      else
        jsonstr="{success:false}"
      end
      render :text=>jsonstr, :layout=>false
    rescue Exception => e
      CommonHelper.infoLogger(session[:user_id],request.env["REMOTE_ADDR"],params[:controller],params[:action],e,"error")
    end
  end
end
